package com.roc.util.constant;

import java.util.HashMap;

import org.apache.commons.lang3.StringUtils;

/**
 * 
 * @author zx-think
 *
 */
public enum MerberFlag {
	
	MERBERFLAG_NO("00","否"),//非会员
	MERBERFLAG_HTX("01","是");//合天下
	

	private String code;
	private String name;
	
	private MerberFlag(String code,String name){
		this.code=code;
		this.name=name;
	}
	
	public static MerberFlag valueOfCode(String code) {
		if (StringUtils.isBlank(code)) {
			throw new IllegalArgumentException("Merchant Status " + code
					+ " is blank");
		}
		for (MerberFlag mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt;
			}
		}
		throw new IllegalArgumentException("Merchant Type " + code
				+ " is not exist");
	}
	
	/**
	 * 通过ID获取中文名称
	 * @param code
	 * @return
	 */
	public static String getName(String code) {
		if (StringUtils.isBlank(code)) {
			throw new IllegalArgumentException("MerberFlag code " + code
					+ " is blank");
		}
		for (MerberFlag mt : values()) {
			if (mt.getCode().equals(code)) {
				return mt.getName();
			}
		}
		throw new IllegalArgumentException("MerberFlag code  " + code
				+ " is not exist");
	}
	
	/**
	 * 获取所有的枚举,以MAP返回
	 * @return
	 */
	public static HashMap<String,String> getAllEnumMap() {
		
		HashMap<String,String> map = new HashMap<String,String>();
		
		for (MerberFlag mt : values()) {
			map.put(mt.getCode(), mt.getName());
		}
		
		return map;
		
	}
	
	public String getCode() {
		return code;
	}

	public String getName() {
		return name;
	}
	
	
	
}
